home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / DOSGRAPH.C < prev    next >
C/C++ Source or Header  |  1992-02-23  |  25KB  |  696 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                       Ver 0.1, Mar. 1990    *
  5. ******************************************************************************
  6. * MSDOS graphical interface for IRIT. Based on intr_lib windowing library.   *
  7. *****************************************************************************/
  8.  
  9. #include <time.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #ifndef DJGCC
  14. #include <conio.h>
  15. #endif /* DJGCC */
  16. #include "graphgen.h"
  17. #include "intr_lib.h"
  18. #include "intr_gr.h"
  19.  
  20. int ViewWindowID, InputWindowID, StatusWindowID, TransWindowID;
  21.  
  22. #ifdef DJGCC
  23. #define NUM_OF_TEXT_LINES 200
  24. #else
  25. #define NUM_OF_TEXT_LINES 50
  26. #endif /* DJGCC */
  27.  
  28. /* Interactive menu setup structure: */
  29. #define INTERACT_NUM_OF_STRINGS        3
  30. #define INTERACT_NUM_OF_SUB_WNDWS_FULL    16
  31. #define INTERACT_NUM_OF_SUB_WNDWS_PART    13
  32. #define INTERACT_SUB_WINDOW_HEIGHT    0.04  /* Actually half Height/Width. */
  33. #define INTERACT_SUB_WINDOW_WIDTH    0.8
  34. #define INTERACT_X_CENTER        ((SW_MAX_X + SW_MIN_X) / 2.0 + 0.02)
  35.  
  36. typedef struct InteractString {
  37.     IntrRType X, Y;
  38.     int Color;
  39.     char *Str;
  40. } InteractString;
  41.  
  42. typedef struct InteractSubWindow {
  43.     IntrRType X, Y;                       /* Center points. */
  44.     GraphicEventType InteractCode;
  45.     int Color,
  46.     TextInside; /* If TRUE, Str will be in window, otherwise left to it. */
  47.     char *Str;
  48. } InteractSubWindow;
  49.  
  50. typedef struct InteractWindowStruct {     /* The interactive menu structures. */
  51.     /* Rotate, Translate, Scale strings: */
  52.     InteractString Strings[INTERACT_NUM_OF_STRINGS];
  53.     InteractSubWindow SubWindows[INTERACT_NUM_OF_SUB_WNDWS_FULL];
  54. } InteractWindowStruct;
  55.  
  56. static IntrBType
  57.     HasStatusWindow = FALSE,
  58.     HasInputWindow = FALSE;
  59.  
  60. static int
  61.     InteractNumOfSubWndws = INTERACT_NUM_OF_SUB_WNDWS_FULL;
  62.     
  63. /* Interactive mode menu set up structure is define below: */
  64. static InteractWindowStruct InteractMenuFull = {
  65.     { { 0.0, -0.60, RED,   "Rotate" },
  66.       { 0.0, -0.28, GREEN, "Translate" },
  67.       { 0.0,  0.04, CYAN,  "Scale" },
  68.     },
  69.     { { 0.0, -0.9,  EVENT_SCR_OBJ_TGL,    CYAN,  TRUE,  "Screen Coords." },
  70.       { 0.0, -0.78, EVENT_PERS_ORTHO_TGL, BLUE,   TRUE,  "Perspectiv" },
  71.       { 0.0, -0.7,  EVENT_PERS_ORTHO_Z,   BLUE,   FALSE, "Z" },
  72.       { 0.0, -0.54, EVENT_ROTATE_X,       RED,    FALSE, "X" }, /* Rot */
  73.       { 0.0, -0.46, EVENT_ROTATE_Y,       RED,    FALSE, "Y" },
  74.       { 0.0, -0.38, EVENT_ROTATE_Z,       RED,    FALSE, "Z" },
  75.       { 0.0, -0.22, EVENT_TRANSLATE_X,    GREEN,  FALSE, "X" }, /* Trans */
  76.       { 0.0, -0.14, EVENT_TRANSLATE_Y,    GREEN,  FALSE, "Y" },
  77.       { 0.0, -0.06, EVENT_TRANSLATE_Z,    GREEN,  FALSE, "Z" },
  78.       { 0.0,  0.1,  EVENT_SCALE,          CYAN,   FALSE, "" },  /* Scale */
  79.       { 0.0,  0.26, EVENT_DEPTH_CUE,      MAGENTA,TRUE,  "Depth cue" },
  80.       { 0.0,  0.42, EVENT_SAVE_GIF,       YELLOW, TRUE,  "Save GIF" },
  81.       { 0.0,  0.5,  EVENT_SAVE_PS,        YELLOW, TRUE,  "Save PS" },
  82.       { 0.0,  0.62, EVENT_SAVE_MATRIX,    YELLOW, TRUE,  "Save Matrix" },
  83.       { 0.0,  0.7,  EVENT_RESET_MATRIX,   YELLOW, TRUE,  "Reset Matrix" },
  84.       { 0.0,  0.85, EVENT_QUIT,           WHITE,  TRUE,  "Quit" },
  85.     }
  86. };
  87. static InteractWindowStruct InteractMenuPartial = {
  88.     { { 0.0, -0.60, RED,   "Rotate" },
  89.       { 0.0, -0.28, GREEN, "Translate" },
  90.       { 0.0,  0.04, CYAN,  "Scale" },
  91.     },
  92.     { { 0.0, -0.9,  EVENT_SCR_OBJ_TGL,    CYAN,  TRUE,  "Screen Coords." },
  93.       { 0.0, -0.78, EVENT_PERS_ORTHO_TGL, BLUE,   TRUE,  "Perspectiv" },
  94.       { 0.0, -0.7,  EVENT_PERS_ORTHO_Z,   BLUE,   FALSE, "Z" },
  95.       { 0.0, -0.54, EVENT_ROTATE_X,       RED,    FALSE, "X" }, /* Rot */
  96.       { 0.0, -0.46, EVENT_ROTATE_Y,       RED,    FALSE, "Y" },
  97.       { 0.0, -0.38, EVENT_ROTATE_Z,       RED,    FALSE, "Z" },
  98.       { 0.0, -0.22, EVENT_TRANSLATE_X,    GREEN,  FALSE, "X" }, /* Trans */
  99.       { 0.0, -0.14, EVENT_TRANSLATE_Y,    GREEN,  FALSE, "Y" },
  100.       { 0.0, -0.06, EVENT_TRANSLATE_Z,    GREEN,  FALSE, "Z" },
  101.       { 0.0,  0.1,  EVENT_SCALE,          CYAN,   FALSE, "" },  /* Scale */
  102.       { 0.0,  0.26, EVENT_DEPTH_CUE,      MAGENTA,TRUE,  "Depth cue" },
  103.       { 0.0,  0.42, EVENT_RESET_MATRIX,   YELLOW, TRUE,  "Reset Matrix" },
  104.       { 0.0,  0.58, EVENT_QUIT,           WHITE,  TRUE,  "Quit" },
  105.     }
  106. };
  107. static InteractWindowStruct *InteractMenu = &InteractMenuFull;
  108.     
  109. static IntrPopUpMenuStruct *PUWndwMenu;
  110. static char *PopUpMenuStrs[] = {
  111.     "Redraw All",
  112.     "Move",
  113.     "Resize",
  114.     "Pop",
  115.     "Push",
  116.     "Zoom",
  117.     "Reset",
  118.     "Headers",
  119. };
  120. #define POP_UP_MENU_SIZE (sizeof(PopUpMenuStrs) / sizeof(char *))
  121.  
  122. static void SetViewWindowFBBox(int WindowID);
  123. static IntrEventType LclGetChar(int *x, int *y);
  124. static void SetBBoxSize(IntrBBoxStruct *BBox, char *GlblTextWindowPos);
  125. static void TransWndwRefreshFunction(int WindowID);
  126. static void TransWndwRefreshFunctionAux(void);
  127. static void StatusWndwRefreshFunction(int WindowID);
  128. static void InteractUpdateMenu(char *Str, int Entry);
  129. static void InputWndwRefreshFunction(int WindowID);
  130. static void SetMaximumBBoxSize(int WindowID);
  131. static void PopUpMenuFunc(int KeyStroke);
  132.  
  133. /******************************************************************************
  134. * A simple test for the Intr_lib library.                      *
  135. ******************************************************************************/
  136. void GGInitIntrLibWindows(int GraphDriver, int FullTransMode)
  137. {
  138.     IntrCursorShapeStruct Cursor;
  139.     IntrBBoxStruct BBox;
  140.     IntrFBBoxStruct FBBox;
  141.  
  142.     IntrSetSaveBackPath(GlblIntrSaveDisk);
  143.     IntrSetSaveBackMethod(GlblIntrSaveMethod);
  144.     IntrSetHandleInternalEvents(TRUE, FALSE);
  145.  
  146. #ifdef __MSDOS__
  147.     GRSetDefaultDriver(GraphDriver);
  148. #endif /* __MSDOS */
  149.  
  150.     if (FullTransMode) {
  151.         InteractNumOfSubWndws = INTERACT_NUM_OF_SUB_WNDWS_FULL;
  152.     InteractMenu = &InteractMenuFull;
  153.     }
  154.     else {
  155.         InteractNumOfSubWndws = INTERACT_NUM_OF_SUB_WNDWS_PART;
  156.     InteractMenu = &InteractMenuPartial;
  157.     }
  158.  
  159.     IntrInit();
  160.  
  161.     IntrSetMouseSensitivity(GlblMouseSensitivity);
  162.     IntrSetInputDevice((GlblMouseExists ? INTR_INPT_DEVICE_MOUSE : 0) |
  163.                (GlblJoystickExists ? INTR_INPT_DEVICE_JOYSTICK : 0) |
  164.                INTR_INPT_DEVICE_KEYBOARD);
  165.  
  166.     IntrRegisterKeyStroke(0x13B /* F1 */, PopUpMenuFunc);
  167.  
  168.     /* Set the default cursor to arrow. */
  169.     Cursor.CursorType = INTR_CURSOR_ARROW;
  170.     IntrSetCursorType(&Cursor);
  171.  
  172.     /* Prepare the pop up menu. */
  173.     PUWndwMenu = IntrPopUpMenuCreate("Windows", PopUpMenuStrs, 0,
  174.                   POP_UP_MENU_SIZE,
  175.                   INTR_COLOR_GREEN, INTR_COLOR_CYAN,
  176.                   INTR_COLOR_YELLOW, INTR_COLOR_MAGENTA,
  177.                                   16, &Cursor);
  178.  
  179.     SetBBoxSize(&BBox, GlblViewWndwPos);
  180.     ViewWindowID = IntrWndwCreate("View",
  181.                   GlblWindowFrameWidth,
  182.                   &BBox,
  183.                   GlblViewFrameColor,
  184.                   GlblViewBackColor,
  185.                   &Cursor,
  186.                   NULL,
  187.                   NULL);
  188.     IntrWndwSetDrawHeader(ViewWindowID, GlblDrawHeader);
  189.     IntrWndwPop(ViewWindowID, TRUE, FALSE);
  190.     SetViewWindowFBBox(ViewWindowID);
  191.     
  192.     SetBBoxSize(&BBox, GlblTransWndwPos);
  193.     TransWindowID = IntrWndwCreate("Transformations",
  194.                    GlblWindowFrameWidth,
  195.                    &BBox,
  196.                    GlblTransFrameColor,
  197.                    GlblTransBackColor,
  198.                    &Cursor,
  199.                    NULL,
  200.                    TransWndwRefreshFunction);
  201.     FBBox.FXmin = FBBox.FYmin = -1.0;
  202.     FBBox.FXmax = FBBox.FYmax =  1.0;
  203.     if (!FullTransMode) FBBox.FYmax =  0.7;
  204.     IntrWndwSetFBBox(TransWindowID, &FBBox);
  205.     IntrWndwSetDrawHeader(TransWindowID, GlblDrawHeader);
  206.     IntrWndwPop(TransWindowID, TRUE, TRUE);
  207.  
  208.     if (HasStatusWindow) {
  209.     SetBBoxSize(&BBox, GlblStatusWndwPos);
  210.     StatusWindowID = IntrWndwCreate("Status",
  211.                     GlblWindowFrameWidth,
  212.                     &BBox,
  213.                     GlblStatusFrameColor,
  214.                     GlblStatusBackColor,
  215.                     &Cursor,
  216.                     NULL,
  217.                     StatusWndwRefreshFunction);
  218.     IntrWndwSetDrawHeader(StatusWindowID, GlblDrawHeader);
  219.     IntrWndwPop(StatusWindowID, TRUE, TRUE);
  220.     }
  221.  
  222.     if (HasInputWindow) {
  223.     SetBBoxSize(&BBox, GlblInputWndwPos);
  224.     InputWindowID = IntrWndwCreate("Input",
  225.                        GlblWindowFrameWidth,
  226.                        &BBox,
  227.                        GlblInputFrameColor,
  228.                        GlblInputBackColor,
  229.                        &Cursor,
  230.                        NULL,
  231.                        InputWndwRefreshFunction);
  232.     IntrTextInitWindow(InputWindowID, TRUE, INTR_COLOR_YELLOW,
  233.                INTR_COLOR_RED, INTR_SCRLBAR_NONE,
  234.                INTR_SCRLBAR_LEFT, NUM_OF_TEXT_LINES, 90);
  235.     IntrWndwSetDrawHeader(InputWindowID, GlblDrawHeader);
  236.     IntrTextSetSmoothScroll(GlblSmoothTextScroll);
  237.     IntrWndwPop(InputWindowID, TRUE, TRUE);
  238.     }
  239.  
  240.     /* Make the get line intr_lib routine use this routine to get chars. */
  241.     GRSetGetKeyFunc(LclGetChar);
  242. }
  243.  
  244. /******************************************************************************
  245. * A function bounded to a quit key.                          *
  246. ******************************************************************************/
  247. void GGClosIntrLibWindows(void)
  248. {
  249.     IntrPopUpMenuDelete(PUWndwMenu);
  250.     IntrWndwDelete(ViewWindowID, FALSE);
  251.     IntrWndwDelete(TransWindowID, FALSE);
  252.     if (HasStatusWindow)
  253.     IntrWndwDelete(StatusWindowID, FALSE);
  254.     if (HasInputWindow)
  255.     IntrWndwDelete(InputWindowID, FALSE);
  256.  
  257.     IntrClose();
  258. }
  259.  
  260. /******************************************************************************
  261. * Wait for events. Basically waits for an event in the Transformation (Menu)  *
  262. * window and returns its interaction code.                              *
  263. ******************************************************************************/
  264. GraphicEventType GGGetGraphicEvent(RealType *ChangeFactor)
  265. {
  266.     int i, x, y;
  267.     GraphicEventType InteractCode;
  268.  
  269.     while (TRUE) {
  270.     IntrRType Wx, Wy;
  271.  
  272.     switch (IntrGetEventWait(&x, &y)) {
  273.         case INTR_EVNT_SELECT:
  274.         if (IntrMapEventToRWindow(TransWindowID, x, y, &Wx, &Wy)) {
  275.             if (Wx < -INTERACT_SUB_WINDOW_WIDTH ||
  276.             Wx > INTERACT_SUB_WINDOW_WIDTH)
  277.             break;
  278.             for (i = 0; i < InteractNumOfSubWndws; i++)
  279.             if (Wy < InteractMenu -> SubWindows[i].Y +
  280.                         INTERACT_SUB_WINDOW_HEIGHT &&
  281.                 Wy > InteractMenu -> SubWindows[i].Y -
  282.                         INTERACT_SUB_WINDOW_HEIGHT) {
  283.                 InteractCode = InteractMenu -> SubWindows[i].InteractCode;
  284.  
  285.                 switch (InteractCode) {
  286.                 case EVENT_SCR_OBJ_TGL:
  287.                     switch (GlblTransformMode) {
  288.                     case TRANS_SCREEN:
  289.                         InteractUpdateMenu("Object Coords.", 0);
  290.                         GlblTransformMode = TRANS_OBJECT;
  291.                         break;
  292.                     case TRANS_OBJECT:
  293.                         InteractUpdateMenu("Screen Coords.", 0);
  294.                         GlblTransformMode = TRANS_SCREEN;
  295.                         break;
  296.                     }
  297.                     break;
  298.                 case EVENT_PERS_ORTHO_TGL:
  299.                     switch (GlblViewMode) {
  300.                     case VIEW_PERSPECTIVE:
  301.                         InteractUpdateMenu("Orthographic", 1);
  302.                         GlblViewMode = VIEW_ORTHOGRAPHIC;
  303.                         break;
  304.                     case VIEW_ORTHOGRAPHIC:
  305.                         InteractUpdateMenu("Perspective", 1);
  306.                         GlblViewMode = VIEW_PERSPECTIVE;
  307.                         break;
  308.                     }
  309.                     break;
  310.                 case EVENT_DEPTH_CUE:
  311.                     GlblDepthCue = !GlblDepthCue;
  312.                     InteractUpdateMenu(
  313.                     GlblDepthCue ? "Depth Cue" : "No Depth Cue",
  314.                     10);
  315.                     break;
  316.                 default:
  317.                     break;
  318.                 }
  319.  
  320.                 *ChangeFactor = Wx / INTERACT_SUB_WINDOW_WIDTH;
  321.                 return InteractCode;
  322.             }
  323.         }
  324.         else {
  325.             PopUpMenuFunc(0);               /* Pop up the main menu. */
  326.         }
  327.         break;
  328.         case INTR_EVNT_ABORT:
  329.         break;
  330.     }
  331.     }
  332. }
  333.  
  334. /******************************************************************************
  335. * Similar to GGGetGraphicEvent above but for intr_lib get graphic line        *
  336. * routine GGGetGraphicLine, so it may activate the pop up menu async.         *
  337. ******************************************************************************/
  338. static IntrEventType LclGetChar(int *x, int *y)
  339. {
  340.     IntrRType Wx, Wy;
  341.     IntrEventType Event;
  342.  
  343.     switch (Event = IntrGetEventWait(x, y)) {
  344.     case INTR_EVNT_SELECT:
  345.         if (!IntrMapEventToRWindow(TransWindowID, *x, *y, &Wx, &Wy)) {
  346.         PopUpMenuFunc(0);                   /* Pop up the main menu. */
  347.         }
  348.         break;
  349.     }
  350.  
  351.     return Event;
  352. }
  353.  
  354. /******************************************************************************
  355. * Enables/Disables (default) the existance of Input and Status windows.       *
  356. * This function should be called BEFORE InitIntrLibWindows above.          *
  357. ******************************************************************************/
  358. void GGSetStatusInputWindows(IntrBType HasStatusWndw, IntrBType HasInputWndw)
  359. {
  360.     HasStatusWindow = HasStatusWndw;
  361.     HasInputWindow = HasInputWndw;
  362. }
  363.  
  364. /*****************************************************************************
  365. *  Routine to test if quit display event - occured - SPACE was hit on         *
  366. * keyboard or right button was clicked on mouse.                 *
  367. *****************************************************************************/
  368. int GGIsAbortKeyPressed(void)
  369. {
  370.     int x, y;
  371.  
  372.     return IntrGetEventNoWait(&x, &y) == INTR_EVNT_ABORT;
  373. }
  374.  
  375. /******************************************************************************
  376. * Parse the position string and set the BBox location.                  *
  377. ******************************************************************************/
  378. static void SetBBoxSize(IntrBBoxStruct *BBox, char *GlblTextWindowPos)
  379. {
  380.     int i;
  381.     IntrRType XYLoc[4];
  382.  
  383.     if (sscanf(GlblTextWindowPos, "%f, %f, %f, %f",
  384.            &XYLoc[0], &XYLoc[1], &XYLoc[2], &XYLoc[3]) != 4) {
  385.     XYLoc[0] = XYLoc[1] = 0.1;
  386.     XYLoc[2] = XYLoc[3] = 0.9;
  387.     }
  388.  
  389.     for (i = 0; i < 4; i++) {
  390.     if (XYLoc[i] < 0.0) XYLoc[i] = 0.0;
  391.     if (XYLoc[i] > 1.0) XYLoc[i] = 1.0;
  392.     }
  393.  
  394.     BBox -> Xmin = (int) (XYLoc[0] * GRScreenMaxX);
  395.     BBox -> Ymin = (int) (XYLoc[1] * GRScreenMaxY);
  396.     BBox -> Xmax = (int) (XYLoc[2] * GRScreenMaxX);
  397.     BBox -> Ymax = (int) (XYLoc[3] * GRScreenMaxY);
  398. }
  399.  
  400.  
  401. /******************************************************************************
  402. * A routine to compute the normalized floating bbox for the provided window.  *
  403. ******************************************************************************/
  404. static void SetViewWindowFBBox(int WindowID)
  405. {
  406.     IntrBBoxStruct *BBox;
  407.     IntrFBBoxStruct FBBox;
  408.     
  409.     /* Compute the aspect ratio of this window and save it so we can match   */
  410.     /* it if the window is resized or zoomed etc.                 */
  411.     BBox = IntrWndwGetBBox(WindowID);
  412.     if (BBox -> _Dy > BBox -> _Dx) {
  413.     /* Normalize the X axis to hold -1 to 1 domain. */
  414.     FBBox.FYmin =                   /* Note the Y axis is flipped. */
  415.          (1.0 / GRScreenAspect) * (((IntrRType) BBox -> _Dy) / BBox -> _Dx);
  416.     FBBox.FYmax = -FBBox.FYmin;
  417.     FBBox.FXmin = -1.0;
  418.     FBBox.FXmax = 1.0;
  419.     }
  420.     else {
  421.     /* Normalize the Y axis to hold -1 to 1 domain. */
  422.     FBBox.FYmin = 1.0;              /* Note the Y axis is flipped. */
  423.         FBBox.FYmax = -1.0;
  424.     FBBox.FXmax =
  425.              GRScreenAspect * (((IntrRType) BBox -> _Dx) / BBox -> _Dy);
  426.     FBBox.FXmin = -FBBox.FXmax;
  427.     }
  428.     IntrWndwSetFBBox(WindowID, &FBBox);
  429. }
  430.  
  431. /******************************************************************************
  432. * A routine invoked when ever the Trans window needs to be refreshed.          *
  433. ******************************************************************************/
  434. static void TransWndwRefreshFunction(int WindowID)
  435. {
  436.     switch (GlblTransformMode) {
  437.     case TRANS_SCREEN:
  438.         InteractMenu -> SubWindows[0].Str = "Screen Coords.";
  439.         break;
  440.     case TRANS_OBJECT:
  441.         InteractMenu -> SubWindows[0].Str = "Object Coords.";
  442.         break;
  443.     }
  444.  
  445.     switch (GlblViewMode) {
  446.     case VIEW_PERSPECTIVE:
  447.         InteractMenu -> SubWindows[1].Str = "Perspective";
  448.         break;
  449.     case VIEW_ORTHOGRAPHIC:
  450.         InteractMenu -> SubWindows[1].Str = "Orthographic";
  451.         break;
  452.     }
  453.  
  454.     if (GlblDepthCue)
  455.     InteractMenu -> SubWindows[10].Str = "Depth Cue";
  456.     else
  457.     InteractMenu -> SubWindows[10].Str = "No Depth Cue";
  458.  
  459.     TransWndwRefreshFunctionAux();        /* Draw the transformation menu. */
  460. }
  461.  
  462. /******************************************************************************
  463. *  Routine to draw the Transformationnu in the Menu window, using the         *
  464. * InteractiveMenu structure defined above.                      *
  465. *  It is assumed that string not inside of SubWindow will be of length 1.     *
  466. ******************************************************************************/
  467. static void TransWndwRefreshFunctionAux(void)
  468. {
  469.     int i;
  470.  
  471.     GRPushTextSetting();
  472.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  473.              GR_TEXT_VJUSTIFY_CENTER);       /* Draw strings centered. */
  474.  
  475.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  476.  
  477.     for (i = 0; i < INTERACT_NUM_OF_STRINGS; i++) {/* Draw strings of struct.*/
  478.     GRSetColor(InteractMenu -> Strings[i].Color);
  479.     IntrWndwRText(InteractMenu -> Strings[i].X,
  480.               InteractMenu -> Strings[i].Y,
  481.               InteractMenu -> Strings[i].Str);
  482.     }
  483.  
  484.     for (i = 0; i < InteractNumOfSubWndws; i++) {
  485.     /* Draw struct sub windows. */
  486.     GRSetColor(InteractMenu -> SubWindows[i].Color);
  487.     /* Draw the frame of the SubWindow: */
  488.     IntrWndwRMoveTo(
  489.         InteractMenu -> SubWindows[i].X - INTERACT_SUB_WINDOW_WIDTH,
  490.         InteractMenu -> SubWindows[i].Y - INTERACT_SUB_WINDOW_HEIGHT);
  491.     IntrWndwRLineTo(
  492.         InteractMenu -> SubWindows[i].X + INTERACT_SUB_WINDOW_WIDTH,
  493.         InteractMenu -> SubWindows[i].Y - INTERACT_SUB_WINDOW_HEIGHT);
  494.     IntrWndwRLineTo(
  495.         InteractMenu -> SubWindows[i].X + INTERACT_SUB_WINDOW_WIDTH,
  496.         InteractMenu -> SubWindows[i].Y + INTERACT_SUB_WINDOW_HEIGHT);
  497.     IntrWndwRLineTo(
  498.         InteractMenu -> SubWindows[i].X - INTERACT_SUB_WINDOW_WIDTH,
  499.         InteractMenu -> SubWindows[i].Y + INTERACT_SUB_WINDOW_HEIGHT);
  500.     IntrWndwRLineTo(
  501.         InteractMenu -> SubWindows[i].X - INTERACT_SUB_WINDOW_WIDTH,
  502.         InteractMenu -> SubWindows[i].Y - INTERACT_SUB_WINDOW_HEIGHT);
  503.  
  504.     /* Now the strings inside (and if outside, a middle vertical line): */
  505.     if (InteractMenu -> SubWindows[i].TextInside)
  506.         IntrWndwRText(InteractMenu -> SubWindows[i].X,
  507.               InteractMenu -> SubWindows[i].Y,
  508.               InteractMenu -> SubWindows[i].Str);
  509.     else {
  510.         IntrWndwRText(InteractMenu -> SubWindows[i].X -
  511.                 INTERACT_SUB_WINDOW_WIDTH - 0.1,
  512.               InteractMenu -> SubWindows[i].Y,
  513.               InteractMenu -> SubWindows[i].Str);
  514.         IntrWndwRLine(InteractMenu -> SubWindows[i].X,
  515.               InteractMenu -> SubWindows[i].Y -
  516.                 INTERACT_SUB_WINDOW_HEIGHT,
  517.               InteractMenu -> SubWindows[i].X,
  518.               InteractMenu -> SubWindows[i].Y +
  519.                 INTERACT_SUB_WINDOW_HEIGHT);
  520.     }
  521.     }
  522.  
  523.     GRPopTextSetting();
  524. }
  525.  
  526. /******************************************************************************
  527. * A routine invoked when ever the Status window needs to be refreshed.          *
  528. ******************************************************************************/
  529. static void StatusWndwRefreshFunction(int WindowID)
  530. {
  531.     GRPushTextSetting();
  532.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  533.              GR_TEXT_VJUSTIFY_CENTER);       /* Draw strings centered. */
  534.  
  535.     GRSetLineStyle(GR_SOLID_LINE, 0, GR_NORM_WIDTH);
  536.  
  537.     GGMySetColor(GREEN);
  538.     IntrWndwRText(0.0, -0.6, "Irit");
  539.  
  540.     GGMySetColor(GREEN);
  541.     IntrWndwRText(0.0, -0.2, VERSION);
  542.     
  543.     GGMySetColor(RED);
  544.     IntrWndwRText(0.0, 0.2, "Core Left");
  545.  
  546.     GRPopTextSetting();
  547. }
  548.  
  549. /*****************************************************************************
  550. *  Routine to update entry Entry with a new string Str.                 *
  551. *****************************************************************************/
  552. static void InteractUpdateMenu(char *Str, int Entry)
  553. {
  554.     GRPushTextSetting();
  555.  
  556.     GRSetTextJustify(GR_TEXT_HJUSTIFY_CENTER,
  557.              GR_TEXT_VJUSTIFY_CENTER);       /* Draw strings centered. */
  558.  
  559.     GRPushViewPort();
  560.     IntrWndwPop(TransWindowID, FALSE, FALSE);
  561.     GGViewPortTransArea();
  562.  
  563.     GRSetColor(BLACK);                    /* Erase the old string. */
  564.     IntrWndwRText(InteractMenu -> SubWindows[Entry].X,
  565.           InteractMenu -> SubWindows[Entry].Y,
  566.           InteractMenu -> SubWindows[Entry].Str);
  567.  
  568.     InteractMenu -> SubWindows[Entry].Str = Str;       /* Update to new one. */
  569.  
  570.     GRSetColor(InteractMenu -> SubWindows[Entry].Color);/* And draw the new. */
  571.     IntrWndwRText(InteractMenu -> SubWindows[Entry].X,
  572.           InteractMenu -> SubWindows[Entry].Y,
  573.           InteractMenu -> SubWindows[Entry].Str);
  574.  
  575.     GRPopViewPort();
  576.  
  577.     GRPopTextSetting();
  578. }
  579.  
  580. /******************************************************************************
  581. * A routine invoked when ever the Input window needs to be refreshed.          *
  582. ******************************************************************************/
  583. static void InputWndwRefreshFunction(int WindowID)
  584. {
  585.     IntrTextWndwRefresh(WindowID);
  586. }
  587.  
  588. /******************************************************************************
  589. * A function bounded to a window handling key.                      *
  590. ******************************************************************************/
  591. static void SetMaximumBBoxSize(int WindowID)
  592. {
  593.    IntrBBoxStruct BBox;
  594.  
  595.    BBox.Xmin = BBox.Ymin = GlblWindowFrameWidth;
  596.    BBox.Xmax = GRScreenMaxX - GlblWindowFrameWidth;
  597.    BBox.Ymax = GRScreenMaxY - GlblWindowFrameWidth;
  598.  
  599.    if (WindowID == InputWindowID)
  600.     BBox.Xmin += IntrWndwScrollBarWidth();
  601.  
  602.    IntrWndwSetResizeBBox(&BBox);
  603. }
  604.  
  605. /******************************************************************************
  606. * A function bounded to a window handling key.                      *
  607. ******************************************************************************/
  608. static void PopUpMenuFunc(int KeyStroke)
  609. {
  610.     int WindowID;
  611.     IntrIntFunc ViewRefreshFunc;
  612.     IntrBBoxStruct BBox;
  613.  
  614.     if (IntrPopUpMenu(PUWndwMenu, 0)) {
  615.     switch (PUWndwMenu -> SelectedIndex) {
  616.         case 0: /* Redraw all windows. */
  617.         IntrWndwRedrawAll();
  618.         break;
  619.         case 1: /* Move window. */
  620.         if (IntrPopUpActive() == 0 &&
  621.             (WindowID = IntrWndwPick()) > 0)
  622.             IntrWndwMove(WindowID, TRUE);
  623.         break;
  624.         case 2: /* Resize window. */
  625.         if (IntrPopUpActive() == 0 &&
  626.             (WindowID = IntrWndwPick()) > 0) {
  627.             SetMaximumBBoxSize(WindowID);
  628.             if (WindowID == ViewWindowID) {
  629.             /* DIsable refresh function since we change aspect. */
  630.             ViewRefreshFunc = IntrWndwGetRefreshFunc(ViewWindowID);
  631.             IntrWndwSetRefreshFunc(ViewWindowID, NULL);
  632.             }
  633.             IntrWndwResize(WindowID, TRUE);
  634.             if (WindowID == ViewWindowID) {
  635.             SetViewWindowFBBox(WindowID);
  636.             IntrWndwSetRefreshFunc(ViewWindowID, ViewRefreshFunc);
  637.             IntrWndwPop(WindowID, TRUE, TRUE);
  638.             }
  639.         }
  640.         break;
  641.         case 3: /* Pop window. */
  642.         if (IntrPopUpActive() == 0 &&
  643.             (WindowID = IntrWndwPick()) > 0)
  644.             IntrWndwPop(WindowID, TRUE, FALSE);
  645.         break;
  646.         case 4: /* Push window. */
  647.         if (IntrPopUpActive() == 0 &&
  648.             (WindowID = IntrWndwPick()) > 0)
  649.             IntrWndwPush(WindowID, TRUE);
  650.         break;
  651.         case 5: /* Zoom window. */
  652.         if (IntrPopUpActive() == 0 &&
  653.             (WindowID = IntrWndwPick()) > 0) {
  654.                 SetMaximumBBoxSize(WindowID);
  655.             if (WindowID == ViewWindowID) {
  656.             /* DIsable refresh function since we change aspect. */
  657.             ViewRefreshFunc = IntrWndwGetRefreshFunc(ViewWindowID);
  658.             IntrWndwSetRefreshFunc(ViewWindowID, NULL);
  659.             }
  660.             IntrWndwFullSize(WindowID, TRUE);
  661.             if (WindowID == ViewWindowID) {
  662.             SetViewWindowFBBox(WindowID);
  663.             IntrWndwSetRefreshFunc(ViewWindowID, ViewRefreshFunc);
  664.             IntrWndwPop(WindowID, TRUE, TRUE);
  665.             }
  666.         }
  667.         break;
  668.         case 6: /* Reset window sizes. */
  669.         SetBBoxSize(&BBox, GlblViewWndwPos);
  670.         IntrWndwSetBBox(ViewWindowID, &BBox);
  671.         SetBBoxSize(&BBox, GlblTransWndwPos);
  672.         IntrWndwSetBBox(TransWindowID, &BBox);
  673.         if (HasStatusWindow) {
  674.             SetBBoxSize(&BBox, GlblStatusWndwPos);
  675.             IntrWndwSetBBox(StatusWindowID, &BBox);
  676.         }
  677.         if (HasInputWindow) {
  678.             SetBBoxSize(&BBox, GlblInputWndwPos);
  679.                 IntrWndwSetBBox(InputWindowID, &BBox);
  680.         }
  681.         IntrWndwRedrawAll();
  682.             break;
  683.         case 7: /* Headers. */
  684.         GlblDrawHeader = !GlblDrawHeader;
  685.         IntrWndwSetDrawHeader(ViewWindowID, GlblDrawHeader);
  686.         IntrWndwSetDrawHeader(TransWindowID, GlblDrawHeader);
  687.         if (HasStatusWindow)
  688.             IntrWndwSetDrawHeader(StatusWindowID, GlblDrawHeader);
  689.         if (HasInputWindow)
  690.             IntrWndwSetDrawHeader(InputWindowID, GlblDrawHeader);
  691.         IntrWndwRedrawAll();
  692.         break;
  693.     }
  694.     }
  695. }
  696.